<?php
namespace app\common\command;

use app\common\lib\Kafka;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;

/**
 * 消费队列命令
 * Class Consumer
 * @package app\common\command
 */
class Rdkafka extends Command
{
    /**
     * 命令配置
     */
    protected function configure()
    {
        $this->setName('rdkafka')
            ->setDescription('rdkafka consumer');
//            ->addArgument('name', Argument::REQUIRED, 'name')
//            ->addArgument('url', Argument::REQUIRED, 'The URL to be subscribed.')
//            ->addArgument('queue', Argument::OPTIONAL, 'The URL to be subscribed.')
//            ->addOption('option', null, Option::VALUE_IS_ARRAY | Option::VALUE_OPTIONAL, 'the options');
    }

    /**
     * 执行命令
     * @param Input $input
     * @param Output $output
     * @return int|void|null
     * @throws \RdKafka\Exception
     */
    protected function execute(Input $input, Output $output)
    {
        $output->write('开始监听：' . date('Y-m-d H:i:s') . PHP_EOL);

        Kafka::getInstance()->consumer();
    }
}
